import cv2
import os


for filename in os.listdir("../images"):  # listdir的参数是文件夹的路径
    filenames = '../images/'+filename

    # 加载灰度图
    img = cv2.imread(filenames, 1)

    detector = cv2.CascadeClassifier(
        '../pack/haarcascade_frontalface_default.xml')

    rects = detector.detectMultiScale(img, scaleFactor=1.1, minNeighbors=2, minSize=(
        10, 10), flags=cv2.CASCADE_SCALE_IMAGE)

    print(rects)
    for (x, y, w, h) in rects:
        # 画矩形框
        face = cv2.rectangle(img, (x, y), (x+w, y+h), (255, 255, 255), 2)
        # face = img[w:h, y:x]

    cv2.namedWindow('imgBox', cv2.WINDOW_NORMAL)
    cv2.imshow('imgBox', face)
    cv2.waitKey(0)
